<template>
    <div class="organization-list">
        <div><TissueTree @tissueIdla="tissueIdla"></TissueTree></div>
        <div class="organization-content-list">
            <div class="content-cotent">

                <div class="cotent-botton">
                    <div class="cotent-botton-input">
                        <el-input
                                placeholder="用户名称"
                                v-model="value1"
                                clearable>
                        </el-input>
                    </div>
                    <div class="cotent-botton-input">
                        <el-input
                                placeholder="帐号"
                                v-model="value2"
                                clearable>
                        </el-input>
                    </div>

                    <div class="cotent-botton-input">
                        <el-select v-model="value3" clearable placeholder="是否启用">
                            <el-option
                                    v-for="item in options1"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value">
                            </el-option>
                        </el-select>
                    </div>
                    <div  class="cotent-botton-checkbox">  <el-checkbox class="cotent-botton-checkboxtext" v-model="checked">查看所有下级组织用户</el-checkbox></div>
                    <div class="cotent-botton-botton-one"  @click="query">查 询</div>
                    <div class="cotent-botton-botton-two" @click="empty">清 空</div>
                </div>
                <div class="cotent-botton">
                    <div class="cotent-botton-botton-one" @click="addUserDetails">
                        新 增
                    </div>
                    <div class="cotent-botton-botton-two" @click="deletDetails">删 除</div>
                    <div class="cotent-botton-botton-two2" @click="resetPsw">重置密码</div>
                    <div class="cotent-botton-botton-two" @click="stateType(2)">启 用</div>
                    <div class="cotent-botton-botton-two" @click="stateType(3)">禁 用</div>
                    <div class="cotent-botton-botton-two2" @click="importUsers">批量导入用户</div>
                </div>
                <UserList :headlist="headlist" :contentlist="list" @refreshContentList="refreshContentList" @selectList="selectList"></UserList>
                <Pagination :totalpag="totalpag" v-on:currentpage="currentpage"></Pagination>
            </div>
            <addUser :dialogFormVisible="showDetails" @close="closeForm" :comeRrom="comeRrom" @refreshList="getlist"></addUser>
            <importFiles :dialogFormVisible="dialogFormVisibleimport" @close="closeFormImport"  @refreshList="getlist"></importFiles>
        </div>

    </div>
</template>

<script>
    import TissueTree from '../common/TissueTree';
    import UserList from '../common/user/UserList';
    import Pagination from '../common/Pagination';
    import importFiles from '../common/Dialog/importFiles';
    import addUser from '../common/Dialog/addUser';
    import distributionProperties from '../common/Dialog/distributionProperties';
    import {isUseAble,organType} from "../../utils/constant"
    export default {
        name: "memberManage",
        data(){
            return{
                dialogFormVisibleimport:false,
                organizationId: this.$store.getters.userData.userMsg.id,//组织id
                comeRrom:0,
                value1:"",
                value2:"",
                value3:"",
                totalpag:0,
                current:1,
                checked:false,
                showDetails:false,
                selectLists:"",
                headlist:{
                    checkout:true,
                    operation:{
                        type:true,
                        fromurl:"memberManage",
                    },
                    list:[
                        {
                            prop:"id",
                            label:"序号",
                            width:"80",
                        },{
                            prop:"account",
                            label:"帐号",
                            width:"170",
                        },{
                            prop:"name",
                            label:"用户姓名",
                            width:"120",
                        }
                        ,{
                            prop:"structName",
                            label:"所属组织",
                            width:"120",
                        }
                        ,{
                            prop:"degree",
                            label:"职位",
                            width:"100",
                        }
                        ,{
                            prop:"roleName",
                            label:"角色",
                            width:"130",
                        }
                        ,{
                            prop:"lastUpdate",
                            label:"更新人",
                            width:"100",
                        }
                        ,{
                            prop:"lastUpdateTime",
                            label:"更新时间",
                            width:"160",
                        }
                        ,{
                            prop:"status",
                            label:"是否启用",
                            width:"100",
                            formatter:function(row, column, cellValue, index){
                                return isUseAble(row.status)
                            }
                        }
                    ]},
                list:[],
                options1:[{
                    value: '1',
                    label: '已启用'
                },{
                    value: '0',
                    label: '已停用'
                }],
            }
        },
        components: {
            TissueTree,
            UserList,
            Pagination,
            addUser,
            distributionProperties,
            importFiles
        },
        mounted(){
            this.getlist();
        },
        methods: {

            //用户列表子组件调用的父组件方法
            refreshContentList(){
                this.getlist();
            },

            //批量导入用户
            importUsers(){
                this.dialogFormVisibleimport=true
            },
            closeFormImport(){
                this.dialogFormVisibleimport=false
            },
            //获取子元素传的值
            tissueIdla(val){
                this.organizationId=val;//获取组织id
                this.getlist();
                console.log("子元素",val)
            },
            //查询
            query(){
                    if(this.value1==""&&this.value2==""&&this.value3==""&&this.checked==false){
                        this.$message({
                            message: '还没输入查询内容哦',
                            type: 'warning'
                        });
                    }else {
                        this.getlist()
                    }
            },
            //清空
            empty(){
                this.value1="";
                this.value2="";
                this.value3="";
                this.checked=false
                this.getlist()
            },
            //选择
            selectList(val){
                this.selectLists=val
            },
            addUserDetails(){
                this.showDetails=true
            },
            closeForm(){
                this.showDetails=false;
            },
            //修改用户状态
            stateType(type){
                let _this = this;
                let params={
                    ids:this.selectLists,
                    type:type
                }
                if(this.selectLists){
                    this.$confirm('确定要修改状态吗？', '确认', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                    }).then(() => {
                        _this.Api.setting.batchUpdateUser(params).then((data)=>{
                            if(data.returnCode==10000){
                                this.getlist()
                                this.$message({
                                    type: 'success',
                                    message: '修改成功!'
                                });
                            }else {
                                this.$message({
                                    type: 'warning',
                                    message: data.msg
                                });
                            }
                        })


                    }).catch(() => {

                    });
                }else {
                    this.$alert("您还没有勾选操作用户", '温馨提示', {
                        confirmButtonText: '确定',
                        callback: action => {
                            this.$message({
                                type: 'info',
                                message: `action: ${ action }`
                            });
                        }
                    });
                }
            },
            //删除用户
            deletDetails(){
                let _this = this;
                let params={
                    userIds:this.selectLists
                }
                if(this.selectLists){
                    this.$confirm('确定要删除吗？', '确认', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                    }).then(() => {
                        _this.Api.setting.deleteUser(params).then((data)=>{
                            if(data.returnCode==10000){
                                this.getlist()
                                this.$message({
                                    type: 'success',
                                    message:"删除成功"
                                });
                            }else {
                                this.$message({
                                    type: 'warning',
                                    message: data.msg
                                });
                            }

                        })


                    }).catch(() => {

                    });
                }else {
                    this.$alert("您还没有勾选操作用户", '温馨提示', {
                        confirmButtonText: '确定',
                        callback: action => {
                            this.$message({
                                type: 'info',
                                message: `action: ${ action }`
                            });
                        }
                    });
                }
            },
            resetPsw() {
                let _this = this;
                let params={
                    userId:this.selectLists
                }
                if(this.selectLists){
                    this.$confirm('确定要重置密码吗？重置密码后为默认密码：888888', '确认', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                    }).then(() => {
                        _this.Api.setting.resetUserPassword(params).then((data)=>{
                            if(data.returnCode==10000){
                                this.getlist()
                                this.$message({
                                    type: 'success',
                                    message: '重置密码成功!'
                                });
                            }else {
                                this.$message({
                                    type: 'warning',
                                    message: data.msg
                                });
                            }

                        })


                    }).catch(() => {

                    });
                }else {
                    this.$alert("您还没有勾选操作用户", '温馨提示', {
                        confirmButtonText: '确定',
                        callback: action => {
                            this.$message({
                                type: 'info',
                                message: `action: ${ action }`
                            });
                        }
                    });
                }

            },
            currentpage(currentpage){
                console.log("当前页，",currentpage)
                this.current=currentpage
                this.getlist()
            },
            getlist(){
                let _this = this;
                if(this.checked==true){
                    var showFollows=1
                }else {
                    var showFollows=0
                }
                let params={
                    current:_this.current,
                    size:10,
                    distributorId:this.organizationId,
                    status:this.value3,
                    account:this.value2,
                    name:this.value1,
                    showFollows:showFollows
                }
                _this.Api.setting.queryUser(params).then((data)=>{
                    _this.totalpag=data.data.total;
                    _this.list=data.data.records;
                })
            }

        }
    }
</script>


<style scoped rel="stylesheet/scss" lang="scss">
    .organization-list{
        display: flex;
        .organization-content-list{
            margin: 20px;
            .content-cotent{
                background-color: #ffffff;
                padding: 24px 32px;
                .content-title{
                    display: flex;
                    margin-bottom: 24px;
                    div{
                        font-size:14px;
                        font-family:PingFangSC-Regular;
                        font-weight:400;
                        color:rgba(51,51,51,0.85);
                        line-height:22px;
                        margin-right: 16px;
                    }
                    .title{
                        font-size:20px;
                        font-family:PingFangSC-Medium;
                        font-weight:500;
                        color:rgba(0,0,0,0.85);
                    }
                }
            }
            .cotent-botton{
                display: flex;
                margin-bottom: 24px;
                .cotent-botton-input{
                    width:200px;
                    height:32px;
                    margin-right: 16px;

                }
                .cotent-botton-checkbox{
                    align-self: center;
                    margin-right: 16px;
                    .cotent-botton-checkboxtext{
                        font-size:14px;
                        font-family:PingFangSC-Regular;
                        font-weight:400;
                        color:rgba(0,0,0,0.65);
                        line-height:22px;
                    }
                }

                .cotent-botton-botton-one{
                    width:65px;
                    height:32px;
                    line-height: 32px;
                    text-align: center;
                    background:rgba(24,144,255,1);
                    border-radius:4px;
                    font-size:14px;
                    font-family:PingFangSC-Regular;
                    font-weight:400;
                    color:rgba(255,255,255,1);
                    margin-right: 16px;
                    cursor: pointer;
                }
                .cotent-botton-botton-two{
                    width:65px;
                    height:32px;
                    line-height: 32px;
                    background:rgba(255,255,255,1);
                    border-radius:4px;
                    border:1px #D9D9D9 solid;
                    font-size:14px;
                    font-family:PingFangSC-Regular;
                    font-weight:400;
                    color:rgba(0,0,0,0.65);
                    text-align: center;
                    margin-right: 16px;
                    cursor: pointer;
                }
                .cotent-botton-botton-two2{
                  padding: 0px 16px;
                    height:32px;
                    line-height: 32px;
                    background:rgba(255,255,255,1);
                    border-radius:4px;
                    border:1px #D9D9D9 solid;
                    font-size:14px;
                    font-family:PingFangSC-Regular;
                    font-weight:400;
                    color:rgba(0,0,0,0.65);
                    text-align: center;
                    margin-right: 16px;
                    cursor: pointer;
                }

            }
        }
    }
</style>